home *** CD-ROM | disk | FTP | other *** search
- /*
-
- CCustomIcon.c
- Superclass: CIsleResFile
-
- Facility to associate custom icons with files and folders
-
- October 8, 1992 isl
-
- */
-
- #include <CCustomIcon.h>
-
- extern OSType gSignature;
-
- /*=====================*/
- /*===---------------===*/
-
- void CCustomIcon::ICustomIcon(void)
- Begin
- itsIconSuite= Null;
-
- CIsleResFile::IResFile();
- End
-
- /*===---------------===*/
-
- void CCustomIcon::FetchIconFamily (short iconID)
- Begin
- Boolean state; // Lockedness of this object
-
- MoveHHi((Handle)this);
- state= Lock(True); // We need a solid address below
-
- FailOSErr( GetIconSuite(&itsIconSuite, iconID, (svAllLargeData+svAllSmallData)) );
-
- Lock(state); // Restore lockedness
- End
-
- /*===---------------===*/
-
- void CCustomIcon::PlaceIconFamily (void)
- Begin
- Handle anIcon= Null; // One icon of the suite
-
- if (IsOpen())
- Close();
-
- Open(fsWrPerm); // Open the file and request write permission, only
-
- TRY
- {
- FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Large1BitMask) );
- DetachResource(anIcon); // Make a duplicate
- FailResError();
- AddResource(anIcon, Large1BitMask, kCustomIconResource, kIconInfo);
- FailResError();
- ForgetResource(anIcon); // Leave it be and get ready for the next
-
- FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Large4BitData) );
- DetachResource(anIcon);
- FailResError();
- AddResource(anIcon, Large4BitData, kCustomIconResource, kIconInfo);
- FailResError();
- ForgetResource(anIcon);
-
- FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Large8BitData) );
- DetachResource(anIcon);
- FailResError();
- AddResource(anIcon, Large8BitData, kCustomIconResource, kIconInfo);
- FailResError();
- ForgetResource(anIcon);
-
- FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Small1BitMask) );
- DetachResource(anIcon);
- FailResError();
- AddResource(anIcon, Small1BitMask, kCustomIconResource, kIconInfo);
- FailResError();
- ForgetResource(anIcon);
-
- FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Small4BitData) );
- DetachResource(anIcon);
- FailResError();
- AddResource(anIcon, Small4BitData, kCustomIconResource, kIconInfo);
- FailResError();
- ForgetResource(anIcon);
-
- FailOSErr( GetIconFromSuite(&anIcon, itsIconSuite, Small8BitData) );
- DetachResource(anIcon);
- FailResError();
- AddResource(anIcon, Small8BitData, kCustomIconResource, kIconInfo);
- FailResError();
- ForgetResource(anIcon);
- }
- CATCH
- {
- ForgetResource(anIcon);
- }
- ENDTRY
-
- Update(); // Reflect the changes
- Close();
- End
-
- /*===---------------===*/
-
- void CCustomIcon::ActivateCustomIcon(void)
- Begin
- CInfoPBRec specs; // The icon file's specs
-
- GetMacCatInfo(&specs); // Get our file's
- specs.hFileInfo.ioFlFndrInfo.fdFlags &= kInitedOff;
- specs.hFileInfo.ioFlFndrInfo.fdFlags |= kCustomIcon;
- SetMacCatInfo(&specs); // For instant effect, make sure the parent folder's modification date is set to now
- End
-
- /*===---------------===*/
-
- void CCustomIcon::Dispose(void)
- Begin
- if (itsIconSuite)
- FailOSErr(DisposeIconSuite(itsIconSuite, True));
-
- inherited::Dispose();
- End
-
- /*===---------------===*/
- /*=====================*/